
import { deepCopy } from "../deepCopy";
import { GOODS_INIT, PAGE_CHANGE } from "../actionCreators/actionTypes";

export let goodsReducer = (state = {
    goodsList: [],
    current: 1, // 当前页码
    defaultCurrent: 1, // 默认当前页码
    defaultPageSize: 4, // 默认一页显示几条
    total: 0         // 总条数
}, action) => {
    let newState = deepCopy(state);
    switch (action.type) {
        case GOODS_INIT:
            newState.goodsList = action.goodsList;
            newState.total = action.total;
            return newState;
        case PAGE_CHANGE:
            newState.current = action.current;
            return newState;

        default:
            return state;
    }
}